#include "enemyplane2.h"
#include "config.h"
Enemyplane2::Enemyplane2() {
    // 敌机资源加载
    m_enemy2.load(ENEMY2_PATH);
    // 敌机位置
    m_X = 0;
    m_Y = 0;
    // 敌机状态
    m_Free = true;
    // 敌机速度
    m_speed = ENEMY2_SPEED;
    // 敌机矩形框（碰撞检测）
    m_Rect.setWidth(m_enemy2.width());
    m_Rect.setHeight(m_enemy2.height());
    m_Rect.moveTo(m_X, m_Y);
}

void Enemyplane2::upadatePosition() {
    // 闲置敌机
    if (m_Free) {
        return;
    }
    m_Y += m_speed;
    m_Rect.moveTo(m_X, m_Y);
    // 如果超过屏幕，重置空闲状态
    if (m_Y >= GAME_HEIGHT + m_Rect.height()) {
        m_Free = true;
    }
}

void Enemyplane2::shoot()
{
    // 累积时间间隔
    m_recorder3++;
    // 未达到间隔
    if (m_recorder3 < BULLET__ENEMY_INTEVal) {
        return;
    }
    m_recorder3 = 0;
    for (int i = 0; i < BULLET_ENEMY_NUM; ++i) {
        if (enemy_bullets[i].m_Free) {
            // 如果空闲，发射
            enemy_bullets[i].m_Free = false;
            // 设置子弹坐标
            enemy_bullets[i].m_X = m_X + m_Rect.width() / 2 - enemy_bullets[i].m_Rect.width() / 2;
            enemy_bullets[i].m_Y = m_Y + m_Rect.height();
            break;
        }
    }
    }

